CategoricalAccuracy metric
Bases: Accuracy
Label-set Jaccard; use for classification or retrieval, not free text.
Formula (per field, Jaccard index over label sets):
Its output range is [0, 1]. It operates at a label level
and can be used for classification or retrieval pipelines.
Unlike Accuracy, this metric considers each element of the list
(or the string value) as one label, comparing label sets rather than
tokenized words.
If labels is provided, accumulation is performed per-label (sklearn-style):
for each label L, a sample is "correct for L" when L's presence in
y_true matches its presence in y_pred. This enables stable
macro/weighted averaging across batches even when some labels are
absent from a given sample, and lets result() return a {label: score}
dict for average=None.
If labels is None, a single global set-Jaccard is computed over the
pooled label values; in that mode average=None returns one scalar
(use labels=... for a per-label breakdown).
Example:
# for single label classification
class ListClassification(synalinks.DataModel):
label: Literal["label", "label_1", "label_2"]
# for multi label classification
class ListClassification(synalinks.DataModel):
labels: List[Literal["label", "label_1", "label_2"]]
# or use it with retrieval pipelines, in that case make sure to mask
# the correct fields.
class AnswerWithReferences(synalinks.DataModel):
sources: List[str]
answer: str
Compilation example:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
average
|
str
|
Type of averaging to be performed across per-field results
in the multi-field case.
Acceptable values are |
None
|
labels
|
list
|
(Optional) Explicit list of label names to track.
When provided, accumulation is per-label across all batches and
|
None
|
name
|
str
|
(Optional) string name of the metric instance. |
'categorical_accuracy'
|
in_mask
|
list
|
(Optional) list of keys to keep to compute the metric. |
None
|
out_mask
|
list
|
(Optional) list of keys to remove to compute the metric. |
None
|
in_mask_pattern
|
str
|
(Optional) Regex pattern; fields whose names match
are kept (combined with |
None
|
out_mask_pattern
|
str
|
(Optional) Regex pattern; fields whose names match
are dropped (combined with |
None
|
Source code in synalinks/src/metrics/accuracy_metrics.py
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 | |
get_config()
Return the serializable config of the metric.
Returns:
| Type | Description |
|---|---|
dict
|
The config dict. |